package com.sdkteam.Others;

import java.io.IOException;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.niusounds.sqlite.SQLiteDAO;
import com.sdkteam.Ailatrieuphu.R;
import com.sdkteam.Database.Charts;
import com.sdkteam.Database.DataBaseHelper;

public class HighScores extends Activity {
	SQLiteDAO data;
	TextView[] playerName = new TextView[5];
	TextView[] PlayerScore = new TextView[5];
	Button backMenu;
	int i;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.charts);

		DataBaseHelper db1 = new DataBaseHelper(this);
		if(db1.checkDataBase()==true){
			
		}else{
			try {
				db1.createDataBase();
			} catch (IOException e) {
				e.printStackTrace();
			}
			db1.close();
		}
		// score = new Score(level);
		backMenu = (Button) findViewById(R.id.back_menu);

		playerName[0] = (TextView) findViewById(R.id.player_name1);
		playerName[1] = (TextView) findViewById(R.id.player_name2);
		playerName[2] = (TextView) findViewById(R.id.player_name3);
		playerName[3] = (TextView) findViewById(R.id.player_name4);
		playerName[4] = (TextView) findViewById(R.id.player_name5);

		PlayerScore[0] = (TextView) findViewById(R.id.player_score1);
		PlayerScore[1] = (TextView) findViewById(R.id.player_score2);
		PlayerScore[2] = (TextView) findViewById(R.id.player_score3);
		PlayerScore[3] = (TextView) findViewById(R.id.player_score4);
		PlayerScore[4] = (TextView) findViewById(R.id.player_score5);

		try {
			data = SQLiteDAO.getInstance(this, "Question", Charts.class);
			List<Charts> list = data.get(Charts.class, null, null,
					"score desc", 5);

			for (i = 0; i < 5; i++) {
				playerName[i].setText(list.get(i).getName());
				PlayerScore[i].setText(fomatString(list.get(i).getScore())
						+ "đ");
			}

		} catch (Exception e) {
			// TODO: handle exception
			for (i = 0; i < 5; i++) {
				playerName[i].setText("Player"+(i+1));
				PlayerScore[i].setText("0đ");
			}
			
		}

		backMenu.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});

	}

	public String fomatString(int score) {
		String s = "0";
		if (score == 100)
			s = "100.000";
		if (score == 400)
			s = "400.000";
		if (score == 600)
			s = "600.000";
		if (score == 1000)
			s = "1.000.000";
		if (score == 2000)
			s = "2.000.000";
		if (score == 3000)
			s = "3.000.000";
		if (score == 6000)
			s = "6.000.000";
		if (score == 10000)
			s = "10.000.000";
		if (score == 14000)
			s = "14.000.000";
		if (score == 22000)
			s = "22.000.000";
		if (score == 30000)
			s = "30.000.000";
		if (score == 40000)
			s = "40.000.000";
		if (score == 60000)
			s = "60.000.000";
		if (score == 85000)
			s = "85.000.000";
		if (score == 150000)
			s = "150.000.000";
		return s;

	}

}
